/**
 * Plan name: Login and register
 * Product: Seam Portal
 */
package test;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author romikoops
 *
 */
public class LoginAndRegistration extends SeleneseTestCaseEx {
	
	@After
	public void setUp() throws Exception {
		super.setUp();
		tc.setEnv("_testtitle", "Register");
	}
	
	/**
	 *Register-Register a new user with valid information 
	 */
	@Test
    public void testRegisterUserValidData() {
	
		repEng.newStep("39. Register User(valid data)");
			
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		launchBrowser();
		openURL("http://hobbes.ontometrics.com/magnetportal/");
		
		//2. Click Register an Account
		click("link=Register an Account.");
		
		//3. Fill in all fields with valid information
		typeByContainsId("email", "test@mail.com");
		typeByContainsId("confirmEmail", "test@mail.com");
		typeByContainsId("password", "test123");
		typeByContainsId("confirmPassword", "test123");
		typeByContainsId("verifyCaptcha", ""); //There is problem getting text from Captcha
		
		//4. Click Register button
		click("//input[@value='Register']");
		
		//A new user should be created successfully
		verifyTitle("success"); // Need for correct title		
		
	}    
	
	public void launchBrowser() {
		browser.start();
		browser.windowMaximize();
	}
	
	public void openURL(String url) {
		browser.open(url);
		browser.waitForPageToLoad(tc.getEnv("waitpageload"));
	}
	
	public void click(String locator) {
		browser.click(locator);
		browser.waitForPageToLoad(tc.getEnv("waitpageload"));
	}
	
	public void typeByContainsId(String textId, String textForTyping) {
		browser.type("//*[contains(@id, '" + textId + "')]", textForTyping);
	}
	
	public void verifyTitle(String expectedTitle) {
		String title = browser.getTitle();
		assertTrue(title.contains(expectedTitle));
	}


}
